<?php
	/**
	 * 自我建造类
	 * Enter description here ...
	 * @author ping
	 *
	 */
	class framework
	{
		private static $self;

		/**
		 * 构造函数
		 * Enter description here ...
		 */
		private function __construct()
		{

		}

		/**
		 * 单例入口
		 * Enter description here ...
		 */
		public static function get_self()
		{
			if (self::$self)
			{
				return self::$self;
			}

			self::$self = new self();

			return self::$self;
		}

		/**
		 * 开始建造
		 * Enter description here ...
		 */
		public function build()
		{
			$this->set_define();
			$this->set_autoload();
			$this->set_time_tools();
			$this->set_config();
			$this->set_php();
			$this->start_session();
		}

		/**
		 * 设置自动载入
		 * Enter description here ...
		 */
		private function set_autoload()
		{
			require dirname(__FILE__) . DIRECTORY_SEPARATOR . 'load.php';
			spl_autoload_register(array('load','autoload'));
		}

		private function start_session()
		{
		    session_start();
		}

		/**
		 * 设置PHP环境
		 * Enter description here ...
		 */
		private function set_php()
		{

		}

		/**
		 * 初始化配置文件
		 * Enter description here ...
		 */
		private function set_config()
		{
			config::get_self()->open('config');
			config::get_self()->open('db');
			config::get_self()->open('cache');
			config::get_self()->open('table');
		}

		/**
		 * 配置时区和记录当前时间
		 * Enter description here ...
		 */
		private function set_time_tools()
		{
			time_tools::set_timezone();
			time_tools::$curr_time = time();
		}

		/**
		 * 初始化全局静态变量
		 * Enter description here ...
		 */
		private function set_define()
		{
			define('ROOT_PATH',    dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR);
		    define('LIBRARY_PATH', ROOT_PATH . 'library' . DIRECTORY_SEPARATOR);
		    define('CONFIG_PATH',  ROOT_PATH . 'config' . DIRECTORY_SEPARATOR);
		    define('MODULE_PATH',  ROOT_PATH . 'module' . DIRECTORY_SEPARATOR);
		    define('DATA_PATH',    ROOT_PATH . 'data' . DIRECTORY_SEPARATOR);
		    define('DS', 		   DIRECTORY_SEPARATOR);
		}
	}